package com.eascs.app.sharepush.service;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.dubbo.config.annotation.Service;
import com.eascs.app.dao.PageResult;
import com.eascs.app.sharepush.dao.SharePushDao;
import com.eascs.sharepush.entity.AppShareInfo;
import com.eascs.sharepush.service.SharePushServvice;
import com.eascs.sharepush.vo.SharePushVo;
import com.eascs.web.sso.User;
import com.eascs.web.sso.UserHolder;

@Service
public class SharePushServviceImpl implements SharePushServvice {
	
	@Autowired
	SharePushDao sharePushDao;

	@Override
	public boolean insertSharePushInfo(AppShareInfo appShareInfo) {
		boolean updateFlag = false;
		boolean insertFlag = false;
		AppShareInfo updateEntity = sharePushDao.findAppShareInfoIsY(appShareInfo.getSystem());
		if(updateEntity != null){
			updateEntity.setIsNew("N");
			updateFlag = sharePushDao.updateAppShareInfo(updateEntity);
		}
		
		User user = UserHolder.getUser();
		appShareInfo.setCreatId(user.getNo());
		appShareInfo.setCreator(user.getCname());
		appShareInfo.setCreatDate(new Date());
		appShareInfo.setUpdateId(user.getNo());
		appShareInfo.setUpdator(user.getCname());
		appShareInfo.setUpdateDate(new Date());
		appShareInfo.setIsNew("Y");
		if(updateFlag){
			insertFlag = sharePushDao.insert(appShareInfo) > 0 ? true : false;
		}
		return insertFlag;
	}

	@Override
	public PageResult<Object[]> querySharePushInfoPage(SharePushVo sharePushVo) {
		return sharePushDao.findShareInfoPage(sharePushVo);
	}

	@Override
	public AppShareInfo querySharePushInfoEntity(String system) {
		return sharePushDao.findAppShareInfoIsY(system);
	}

}
